package com.lianxian.xindong.commonsdk.core;

import android.content.Context;

import com.danikula.videocache.HttpProxyCacheServer;
import com.hxb.library.base.BaseApplication;
import com.hxb.library.utils.LogUtils;
import com.lianxian.xindong.commonsdk.utils.MyFileNameGenerator;
import com.wanjian.cockroach.Cockroach;

/**
 * @author: HeXingBo
 * @date: 2022/11/17
 * @description：
 */
public class MyBaseApp extends BaseApplication {


    private HttpProxyCacheServer proxy;

    public static HttpProxyCacheServer getProxy(Context context) {
        MyBaseApp app = (MyBaseApp) context.getApplicationContext();
        return app.proxy == null ? (app.proxy = app.newProxy()) : app.proxy;
    }

    private HttpProxyCacheServer newProxy() {
        return new HttpProxyCacheServer.Builder(this)
                .maxCacheSize(1024 * 1024 * 1024)       // 1 Gb for cache
                .fileNameGenerator(new MyFileNameGenerator())
                .build();
    }

    @Override
    public void onCreate() {
        super.onCreate();
        initCash();
    }

    protected void initCash() {
        Cockroach.install(new Cockroach.ExceptionHandler() {

            @Override
            public void handlerException(final Thread thread, final Throwable throwable) {
                LogUtils.errorInfo("CockroachException:" + thread + "<----" + "/n" + "--->" + throwable);
                //异常手动上报
            }
        });
    }
}
